<?php
class Div_Container {
    private $Body;
    private $Name;
    private $Type;
    private $classList;

    function __construct($Type, $Name) {
        $this->Name = $Name;
        $this->Type = $Type;
        $this->classList =  array(); 
    }

    public function addContent($str) {
        $this->Body .= $str;
    }
    
    public function addClass($className){
        $this->classList[] = $className;//add element to the end of the array
    }


    public function output() {
        echo $this->toString();
    }

    public function toString() {
        $str = "\n" . '<div';
        $classString = implode(' ', $this->classList);
        if($this->Type == 'id')
        {
            if(strlen($classString) > 0)
            {
                $str .= ' ' . $this->Type . '="' . $this->Name . '"' . ' ' . 'class="' . $classString . '"'; 
            }
            else{
                $str .= ' ' . $this->Type . '="' . $this->Name . '"'; 
            }
             
        }
        elseif($this->Type == 'class'){
            if(strlen($classString) > 0)
            {
                $str .= ' ' . $this->Type . '="' . $this->Name . ' ' . $classString . '"'; 
            }
            else{
                $str .= ' ' . $this->Type . '="' . $this->Name . '"'; 
            }
        }
        $str .= '>';
        $str .= $this->Body;
        $str .= "\n" . '</div>';
        return $str;
    }

}

?>
